<template>
  <div>
    <el-card>
      <el-form ref="form" :model="form" class="form" :inline="true" size="mini">
        <el-form-item label="用户ID/昵称" class="input">
          <el-input v-model.number="input" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="推广收益筛选">
          <el-date-picker
            v-model="time"
             type="daterange"
            value-format="timestamp"
             :clearable="false"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            @change="change"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-row type="flex" justify="end">
        <el-col :span="6">
          <el-button type="primary" size="small" ref="check" @click="search"
            >查询</el-button
          >
          <el-button size="small"  @click="resetForm()">重置</el-button>
        </el-col>
      </el-row>
    </el-card>
    <p><span class="num">推广人数量：{{promoter}}</span> <span>推广店铺总数：{{shopNum}}</span></p>
    <el-card>
      <el-table border :data="tableData" row-key="id" class="customer-table">
        <el-table-column label="用户ID" prop="id" align="center" />
        <el-table-column label="用户昵称" prop="name" align="center" />
        <el-table-column label="推广人联系电话" prop="phone" align="center" />
        <el-table-column label="推广数量" prop="num" align="center" />
        <el-table-column label="推广收益" prop="get" align="center" />
        <el-table-column align="center" label="操作">
          <template slot-scope="{row}">
            <el-button size="mini" @click="detail(row.id)">推广详情</el-button>
          </template>
        </el-table-column>
      </el-table>
       <el-row type="flex" justify="center" align="middle" style="height: 60px">
        <el-pagination
           :current-page="page.page"
            :page-size="page.size"
            :total="page.total"
            :page-sizes="[2, 3, 5, 10]"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="changePage"
        >
        </el-pagination>
      </el-row>
      </el-card
    >
  </div>
</template>

<script>
import { queryFn } from '@/utils'// 多选项查询
import {
  getpromoteList, searchuserId

} from '@/api/promoteList.js'
export default {
  data () {
    return {
      time: '',
      input: null,
      form: {
        time_gte: '',
        time_lte: ''
      },
      page: {
        page: 1,
        size: 5,
        total: 12
      },
      tableData: []
    }
  },
  computed: {
    promoter () {
      return this.tableData.length
    },
    shopNum () {
      return this.tableData.reduce((sum, obj) => sum + obj.num, 0)
    }
  },
  created () {
    // 获取列表数据
    this.getpromoteList()
  },
  methods: {
    // 获取数据列表
    async getpromoteList () {
      const { data } = await getpromoteList(
        {
          _page: this.page.page,
          _limit: this.page.size
        }
      )
      this.tableData = data
      // console.log('获取数据列表')
    },
    change (v) {
      console.log(v)
      // if (!v) return
      this.form.time_gte = v[0]
      this.form.time_lte = v[1]
    },
    // 查询
    async search () {
      const obj = queryFn(this.form)
      console.log(obj)
      // console.log(typeof this.input)
      // 判断输入内容
      if (typeof this.input === 'number') {
        obj.id = this.input
        console.log(obj)
      } else if (typeof this.input === 'string') {
        obj.name = this.input
        console.log(obj)
      }
      const { data } = await searchuserId(obj)
      console.log(data)
      this.tableData = data
      this.page.total = this.tableData.length
      this.input = null
      this.time = []
    },
    // 重置
    resetForm () {
      this.input = null
      this.time = []
      this.getpromoteList()
    },
    detail (id) {
      console.log(id)
      this.$router.push({ path: `/detail/:${id}`, query: { id: id } })
    },
    // 分页
    changePage (newpage) {
      this.page.page = newpage
      // console.log(newpage)
      this.getpromoteList({
        _page: this.page.page,
        _limit: this.page.size
      })
    },
    handleSizeChange (newsize) {
      this.page.size = newsize
      // console.log(newsize)
      this.getpromoteList({
        _page: this.page.page,
        _limit: this.page.size
      })
    }
  }
}
</script>

<style lang="less" scoped>
.form {
  box-sizing: border-box;
}
/deep/.customer-table th {
  border: none;
  // background-color: rgb(170, 56, 56);
  color: white;
  // border-radius: 5px;
}
.customer-table /deep/ th.el-table__cell.is-leaf {
  background-color: rgb(98, 131, 240);

  border: none;
}
// .el-table {
//   background-color: rgb(71, 100, 138);
// }
.customer-table /deep/ .el-table__row > td {
  border: none;
}
// .customer-table /deep/ .el-table__row > th {
//   border: none;
// }
.el-button + .el-button {
  margin-left: 30px;
}
.el-form--inline .el-form-item {
  margin-right: 120px;
}
.customer-table th {
  border: none;
}
.customer-table td,
.customer-table th.is-leaf {
  border: none;
}
// 表格最外边框
.el-table--border,
.el-table--group {
  border: none;
}
// 头部边框
.customer-table thead tr th.is-leaf {
  border: 1px solid #ebeef5;
  border-right: none;
}
.customer-table thead tr th:nth-last-of-type(2) {
  border-right: 1px solid #ebeef5;
}
// 表格最外层边框-底部边框
.el-table--border::after,
.el-table--group::after {
  width: 0;
}
.customer-table::before {
  width: 0;
}
.customer-table .el-table__fixed-right::before,
.el-table__fixed::before {
  width: 0;
}
// 表格有滚动时表格头边框
.el-table--border th.gutter:last-of-type {
  border: 1px solid #ebeef5;
  border-left: none;
}
.num{
  margin-right: 30px;
}
</style>
